const Actions = require('./actions');
const DB = require('app/db.js');
import { Storage } from 'clientConfig/util/StoreData'
import { Toast } from 'saltui';
import { Control } from 'react-keeper';
module.exports = Reflux.createStore({
    listenables: [Actions],
    data: {

    },
    onGetRepairTypeList: function (params, cb) {
        let t = this;
        DB.Teacher.get_repair_typeList({
            schoolId: Storage.get('user.schoolId'),
        })
            .then((content) => {
                if (content && content.code == 1) {
                    if (content && content.data) {
                        content = content.data.list;
                        t.data.listdata = content;
                        t.updateComponent();
                    }

                }else{
                    Toast.show({
                        type: 'error',
                        content: '系统异常'
                    });
                }
            })
            .catch(function (error) {
                Toast.show({
                    type: 'error',
                    content: '系统异常'
                });
            });
    },
    onSubmit: function (params, cb) {
        let t = this;
        let config = {...params,schoolId:Storage.get('user.schoolId'),teacherId:Storage.get('user.teacherId')};
        let url = "/app/repair/teacher/fd/tchSaveRepair?schoolId=" + config.schoolId + "&teacherId=" + config.teacherId + "&repairCode=" + config.repairCode + "&repairType=" + config.repairType + "&description=" + config.description + "&contacts=" + config.contacts + "&phone=" + config.phone+"&repairAddress="+config.repairAddress;
        Toast.show({
            type: 'loading',
            content: '发布中',
            hasMask: true,
            duration: 300000,
        });
        fetch(url, {
            method: "POST",
            body: params.formData
        }).then(function (response) {
            return response.json();
        }).then(function (result) {
            Toast.hide(() => {
            });
            if (result.content&&result.content.code == 1) {
                Toast.show({
                    type: 'success',
                    content: '发布成功'
                });
                Control.go(-1);
            }else{
                Toast.show({
                    type: 'error',
                    content: '系统异常'
                });
            }
        }, function (error) {
            Toast.hide(() => {
            });
            Toast.show({
                type: 'error',
                content: '系统异常'
            });
        })
    },
    updateComponent: function () {
        this.trigger(this.data);
    }
});
